package com.example.othree.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.othree.common.PageParam;
import com.example.othree.common.R;
import com.example.othree.entity.InterfaceData;
import com.example.othree.service.InterfaceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/api")
public class InterfaceController {
    @Autowired
    private InterfaceService interfaceService;

    @PostMapping("/interface/create")
    @ApiOperation("新增")
    public R create(@RequestBody InterfaceData interfaceData){
        return interfaceService.save(interfaceData) ? R.ok() : R.error();
    }

    @PostMapping("/interface/saveBatch")
    @ApiOperation("批量新增")
    public R saveBatch(@RequestBody List<InterfaceData> interfaceData){
        return interfaceService.saveBatch(interfaceData) ? R.ok() : R.error();
    }

    @GetMapping("/interface/list")
    @ApiOperation("查询列表")
    public List<InterfaceData> list(){
        return interfaceService.list();
    }

    @PostMapping("/interface/update")
    @ApiOperation("修改")
    public R update(@RequestBody InterfaceData interfaceData){
        return interfaceService.updateById(interfaceData) ? R.ok() : R.error();
    }

    @PostMapping("/interface/delete/{id}")
    @ApiOperation("删除")
    public R delete(@PathVariable Integer id){
        return interfaceService.removeById(id) ? R.ok() : R.error();
    }

    @PostMapping("/interface/listPage")
    @ApiOperation("查询、分页")
    public R listPage(@RequestBody PageParam pageParam){
        HashMap param = pageParam.getParam();

        Page<InterfaceData> page = new Page();
        page.setCurrent(pageParam.getPageNum());
        page.setSize(pageParam.getPageSize());

        LambdaQueryWrapper<InterfaceData> lambdaQueryWrapper = new LambdaQueryWrapper();

        IPage result = interfaceService.PageList(page, lambdaQueryWrapper);

        return R.ok().data("result", result);
    }









}
